home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
program
/
4cmp22s.zip
/
EXEC.4TH
< prev
next >
Wrap
Text File
|
1994-10-30
|
2KB
|
64 lines
\ DOS EXECUTE LIBRARY
\ Contents Copyright (C) 1991 by Thomas Almy
\ Revised 6/94 by Tom Almy
\ Permission is granted to registered users of ForthCMP to sell or distribute
\ computer programs incorporating the compiled contents of this file.
\ This file should be loaded at the start of the program. The
\ STRINGS library must be loaded, and loaded before this file.
.( Loading EXEC) CR
10 HEX
DSEG
CREATE xpb 0E ALLOT
0 xpb ! -1 xpb 6 + ! -1 xpb 8 + ! -1 xpb 0A + ! -1 xpb 0C + !
CSEG
CREATE ssav 0 , 0 ,
DSEG
\ the code for exec could be optimized based on SEPSSEG? and SEPDSEG?
\ either or both being off, but it would not make that much difference
\ in code size.
\ code 9C is PUSHF, 9D is POPF
1 1 IN/OUT
CODE exec ( ^ASCIIZCommand -- failFlag )
BP PUSH CSEG 9C C, DS PUSHSEG
AX DX MOV
CS: ssav CELL+ [] SS <SEG SP CS: ssav [] MOV
AX DS <SEG AX ES >SEG
4B00 # AX MOV
xpb # BX MOV
21 INT
CS: ssav CELL+ [] SS >SEG
CS: ssav [] SP MOV
DS POPSEG 9D C, BP POP
<U ~ IF, AX AX XOR THEN, RET
END-CODE
DSEG
CREATE crChr 3 ALLOT
0D crChr C! \ crChr 1 is string consisting of CR only
20 crChr 1+ C! \ while crChr 1+ 1 is string consisting of BL only
0 crChr CELL+ C! \ and crChr CELL+ is counted zero length string
2 1 IN/OUT
: spawn ( ^command ^args -- failFlag )
crChr 1+ 1 ROT COUNT STRCAT
crChr 1 STRCAT STRPCK -1 OVER +!
xpb CELL+ ! ?DS: xpb 4 + !
ASCIIZ exec
;
2 0 IN/OUT
: EXEC
S" COMSPEC" STR>DSEG getenv ?DUP IF
-ROT DUP IF \ program to run
S" /C " STR>DSEG 2SWAP STRCAT STRPCK
ELSE 2DROP crChr CELL+ THEN
spawn DROP
ELSE ." No COMSPEC" BYE THEN ;
0A = [IF] DECIMAL [THEN]